home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / hotkey-setup < prev    next >
Text File  |  2008-10-15  |  5KB  |  215 lines

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          hotkey-setup
  4. # Required-Start:    $remote_fs $syslog
  5. # Required-Stop:     $remote_fs $syslog
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      1
  8. # Short-Description: Set up laptop keys to generate keycodes.
  9. ### END INIT INFO
  10.  
  11. # do not run if not package is not installed
  12. test -x /usr/sbin/dumpkeycodes || exit 0
  13.  
  14. manufacturer=`dmidecode --string system-manufacturer`
  15. name=`dmidecode --string system-product-name`
  16. version=`dmidecode --string system-version`
  17.  
  18. SAVED_STATE=/var/run/hotkey-setup
  19. THINKPAD_LOCKFILE=$SAVED_STATE.thinkpad-keys
  20. THINKPAD_HOTKEY_MASK=/sys/devices/platform/thinkpad_acpi/hotkey_mask
  21. THINKPAD_KEYS=/usr/sbin/thinkpad-keys
  22. THINKPAD_HOTKEY_MASK_RECOMMENDED=/sys/devices/platform/thinkpad_acpi/hotkey_recommended_mask
  23.  
  24. xorg_driver() {
  25.     if [ -e /etc/X11/xorg.conf ] ; then
  26.     driver=$(sed -n -e '/^[ \t]*section[ \\t]*"device"/I,/^[ \t]*endsection/I{/^[ \t]*driver[ \t]*/I{s/^[ \t]*driver[ \t]*"*//I;s/"*[ \t]*$//;p}}' /etc/X11/xorg.conf)
  27.     fi
  28.     if [ -z "$driver" ] ; then
  29.     vendor=$(lspci | grep VGA | head -1)
  30.     case $vendor in
  31.         *Intel*)
  32.             driver=intel
  33.         ;;
  34.         *AMD*)
  35.             driver=ati
  36.         ;;
  37.         *ATI*)
  38.             driver=ati
  39.         ;;
  40.     esac
  41.     fi
  42.     echo $driver
  43. }
  44.  
  45. do_video () {
  46.     VIDEO=`xorg_driver`
  47.     case $VIDEO in
  48.     intel|ati|radeon)
  49.         for x in /proc/acpi/video/*/DOS; do
  50.         if [ -e "$x" ]; then
  51.             echo -n 7 >$x;
  52.         fi
  53.         done
  54.     ;;
  55.     esac
  56. }
  57.  
  58. # This is here because it needs to be executed both if we have a
  59. # Lenovo that also IDs as a ThinkPad, or if we have a real IBM one.
  60. do_thinkpad () {
  61.     . /usr/share/hotkey-setup/ibm.hk
  62.     modprobe thinkpad-acpi || return 1
  63.  
  64.     thinkpad_keys_args="$1"
  65.  
  66.     # Unconditionally enable brightness and volume groups
  67.     # Try to enable ThinkPad key
  68.     recommended_hotkey_mask=$(cat $THINKPAD_HOTKEY_MASK_RECOMMENDED)
  69.     wanted_hotkey_mask=$(($recommended_hotkey_mask | $TP_NVRAM_HKEY_GROUP_BRIGHTNESS | $TP_NVRAM_HKEY_GROUP_VOLUME | $TP_ACPI_HKEY_THINKPAD_MASK))
  70.  
  71.     echo $wanted_hotkey_mask > $THINKPAD_HOTKEY_MASK
  72.     accepted_hotkey_mask=$(cat $THINKPAD_HOTKEY_MASK)
  73.  
  74.     # If the ThinkPad key bit was accepted, we don't need the polling daemon
  75.     if [ $(($accepted_hotkey_mask & $TP_ACPI_HKEY_THINKPAD_MASK)) -eq 0 ] && test -x $THINKPAD_KEYS; then
  76.         if [ ! -c /dev/input/uinput ]; then
  77.             modprobe uinput
  78.         fi
  79.         if [ ! -c /dev/nvram ]; then
  80.             modprobe nvram
  81.         fi
  82.         $THINKPAD_KEYS $thinkpad_keys_args && touch $THINKPAD_LOCKFILE
  83.     fi
  84. }
  85.  
  86. case "$1" in
  87.     start)
  88.  
  89. # This entire block does nothing on desktops right now
  90.     if laptop-detect; then
  91.  
  92.     do_video
  93.  
  94.     /usr/sbin/dumpkeycodes >$SAVED_STATE
  95.     
  96.     if [ $? -gt 0 ]; then
  97.     rm -f $SAVED_STATE
  98.     fi
  99.  
  100.     . /usr/share/hotkey-setup/key-constants
  101.  
  102.     case "$manufacturer" in
  103.     Acer*)
  104.     . /usr/share/hotkey-setup/acer.hk
  105.     case "$name" in
  106.         Aspire\ 16*)
  107.         . /usr/share/hotkey-setup/acer-aspire-1600.hk
  108.         ;;
  109.     esac
  110.     ;;
  111.  
  112.     ASUS*)
  113.     . /usr/share/hotkey-setup/asus.hk
  114.     ;;
  115.  
  116.     Compaq*)
  117.     case "$name" in
  118.         Armada*E500*|Evo*N620*)
  119.         . /usr/share/hotkey-setup/compaq.hk
  120.         ;;
  121.     esac
  122.     ;;
  123.  
  124.     Dell*)
  125.     . /usr/share/hotkey-setup/dell.hk
  126.     ;;
  127.  
  128.     Hewlett-Packard*)
  129.     # Load this _first_, so that it can be overridden
  130.     . /usr/share/hotkey-setup/hp.hk
  131.     case "$name" in
  132.         # Please open a bug if uncommenting these "Presario" entries works for you...
  133.         #*Presario\ V2000*)
  134.         #. /usr/share/hotkey-setup/hp-v2000.hk
  135.         #;;
  136.         *Tablet*|*tc*)
  137.         . /usr/share/hotkey-setup/hp-tablet.hk
  138.         ;;
  139.     esac
  140.     ;;
  141.  
  142.     IBM*)
  143.     do_thinkpad IBM
  144.     ;;
  145.  
  146.     LENOVO*)
  147.     case "$version" in
  148.         *Think[Pp]ad*)
  149.         do_thinkpad --no-brightness
  150.         ;;
  151.         *)
  152.         . /usr/share/hotkey-setup/lenovo.hk
  153.         ;;
  154.     esac
  155.     ;;
  156.     
  157.     MEDION*)
  158.     case "$name" in
  159.         *FID2060*)
  160.         . /usr/share/hotkey-setup/medion-md6200.hk
  161.         ;;
  162.     esac
  163.     ;;
  164.  
  165.     MICRO-STAR*)
  166.     case "$name" in
  167.         *INFINITY*)
  168.         . /usr/share/hotkey-setup/micro-star-infinity.hk
  169.         ;;
  170.     esac
  171.     ;;
  172.  
  173.     Samsung*|SAMSUNG*)
  174.     . /usr/share/hotkey-setup/samsung.hk
  175.     ;;
  176.  
  177.     Sony*)
  178.     modprobe sonypi; # Needed to get hotkey events
  179.     modprobe sony-laptop
  180.     ;;
  181.  
  182.         FUJITSU\ SIEMENS)
  183.         case "$name" in
  184.             AMILO\ Pa\ 2548)
  185.             . /usr/share/hotkey-setup/fujitsu-siemens-pa2548.hk
  186.             ;;
  187.         esac
  188.         ;;
  189.  
  190.     *)
  191.     . /usr/share/hotkey-setup/default.hk    
  192.     esac
  193.     . /usr/share/hotkey-setup/generic.hk
  194.     fi
  195.     ;;
  196.     stop)
  197.     if [ -f $THINKPAD_LOCKFILE ]; then
  198.         pid=`pidof thinkpad-keys`
  199.         if [ "$pid" ] ; then
  200.             kill $pid || true
  201.         fi
  202.         rm -f $THINKPAD_LOCKFILE
  203.     fi
  204.     if [ -f $SAVED_STATE ]; then
  205.         setkeycodes $(cat $SAVED_STATE) || true
  206.     fi
  207.     ;;
  208.     restart|force-reload)
  209.     $0 stop || true
  210.     $0 start
  211.     ;;
  212. esac
  213.  
  214. exit 0
  215.